MySQL DELETE Statement
The DELETE
statement in mysql is used to delete the records in the table. We can delete(remove) the records by specifying the condition in where
clause.
Syntax for DELETE statement
DELETE FROM table_name WHERE condition;
If the condition is specified then it will delete the records from the table that satisfies the condition.
If no condition is specified using where
clause, then all the records in the table will be deleted.
Consider the following table.
empno | name | age | role | location |
---|---|---|---|---|
001 | Andrew | 30 | Manager | India |
002 | Beslin | 28 | Business Analyst | India |
003 | Joanna | 23 | Senior Developer | USA |
004 | Rayan | 26 | Technical Lead | Canada |
To delete the employee
with the empno
004 we use the following query
delete from employee where empno=004;
We can also delete using the name with the following query
delete from employee where name='Rayan';
Delete all records
To delete all the records in the table we provide delete statement without any condition.
Syntax to delete all records
delete from employee;